package com.hdax.dm.controller;


import com.hdax.dm.common.CommonResponse;
import com.hdax.dm.common.ResponseUtil;
import com.hdax.dm.exception.DmException;
import com.hdax.dm.service.DmLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/user/")
public class LoginController {


    @Autowired
    private DmLoginService dmLoginService;

    @PostMapping("/login")
    public CommonResponse login(@RequestBody Map<String,String> params){
        String phone = params.get("phone");
        String password = params.get("password");
        return dmLoginService.login(phone,password);
    }

    @ExceptionHandler(value = {DmException.class})
    public CommonResponse exceptionHandler(DmException e){

        if(e instanceof DmException)
            return ResponseUtil.returnSuccess(e);
        return ResponseUtil.returnSuccess(e);
    }

}
